package com.firewolf.rbac.controller;

import com.firewolf.rbac.pojo.Menu;
import com.firewolf.rbac.service.MenuService;
import com.firewolf.rbac.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 作者：刘兴
 * 时间:19/3/3
 **/
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @GetMapping("/all")
    public List<Menu> findAll() {
        return menuService.findAll();
    }

    @PostMapping
    public ResponseVO save(Menu menu) {
        try {
            menuService.save(menu);
        } catch (Exception e) {
            return ResponseVO.error("保存菜单失败");
        }
        return ResponseVO.ok("保存菜单成功");
    }

}
